package vj.linkedlist.utils;

import vj.linkedlist.Node;

public class LinkedListUtils {

	public static void printList(Node head) {
		Node node = head;
		while(node != null) {
			System.out.print(node.data + " ");
			node = node.next;
		}
		System.out.println();
	}
	
	public static Node reverse(Node head) {
		Node res = null; // res points to the head of the reversed list
		Node cur = head, next;
		while(cur != null) {
			next = cur.next; // save the next node before overwriting
			cur.next = res;
			res = cur;
			cur = next;
		}
		return res;
	}
	
}
